package com.camunda.workflow.camunda.query;

import com.camunda.workflow.camunda.provider.CustomReadOnlyIdentityProvider;
import org.camunda.bpm.engine.identity.Group;
import org.camunda.bpm.engine.impl.GroupQueryImpl;
import org.camunda.bpm.engine.impl.Page;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
import org.camunda.bpm.engine.impl.interceptor.CommandExecutor;

import java.util.List;

public class CustomGroupQueryImpl extends GroupQueryImpl {
    public CustomGroupQueryImpl() {
        super();
    }
    public CustomGroupQueryImpl(CommandExecutor commandExecutor) {
        super(commandExecutor);
    }
    public long executeCount(CommandContext commandContext) {
        checkQueryOk();
        final CustomReadOnlyIdentityProvider identityProvider = getIdentityProvider(commandContext);
        return identityProvider.findGroupCountByQueryCriteria(this);
    }

    public List<Group> executeList(CommandContext commandContext, Page page) {
        checkQueryOk();
        final CustomReadOnlyIdentityProvider identityProvider = getIdentityProvider(commandContext);
        return identityProvider.findGroupByQueryCriteria(this);
    }

    protected CustomReadOnlyIdentityProvider getIdentityProvider(CommandContext commandContext) {
        return (CustomReadOnlyIdentityProvider) commandContext.getReadOnlyIdentityProvider();
    }

}
